package com.admin.action.return_book_action;

import com.admin.Action;
import com.admin.service.admin_operate_service.AdminOperateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 归还书籍Action
 */

public class ReturnBookAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }


        String bookId = request.getParameter("id");
        String idCard=request.getParameter("card");

        System.out.println("id"+bookId+"card"+idCard);
        AdminOperateServiceImpl adminOperateService = new AdminOperateServiceImpl();

        boolean b = adminOperateService.returnBookById(bookId, idCard);
        if (b){
            out.print(true);
        }else {
            out.print(false);
        }
    }
 
}
